package dwz.common.util;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 判断注单的类型
 * @author Administrator
 *
 */
public class CheckNumberType {
	public static int check(String haoma){
		List<String> patternList = patterns();
		int flag = -1;
		
		for(int i = 0; i < patternList.size(); i++){
		
			if(Pattern.matches(patternList.get(i), haoma)){
				System.out.println(Pattern.matches(patternList.get(i), haoma));
				flag = i + 1;
			}
		}
		System.out.println(flag);
		return flag;
	}
	/**
	 * 处理14中类型
	 * @return
	 */
	public static List<String> patterns(){
		
		List<String> pattern = new ArrayList<String>();
		String erziding1 = "^\\d{2}[Xx]{2}$"; //12XX
		String erziding2 = "^\\d{1}[Xx]\\d{1}[Xx]$"; // 1X2X;
		String erziding3 = "^\\d{1}[Xx]{2}\\d{1}$"; //1XX2;
		String erziding4 = "^[Xx]{2}\\d{2}$"; //XX12;
		String erziding5 = "^[Xx]{1}\\d{1}[Xx]\\d{1}$"; //X1X2;
		String erziding6 = "^[Xx]{1}\\d{2}[Xx]$"; //X12X;
		
		String sanziding1 = "^[Xx]\\d{3}$"; //X123形式的号码
		String sanziding2 = "^\\d{1}[Xx]\\d{2}$"; //1X23形式的号码
		String sanziding3 = "^\\d{2}[Xx]\\d{1}$"; //12X3形式的号码
		String sanziding4 = "^\\d{3}[Xx]$"; //123X形式的号码
		
		String siziding = "^\\d{4}$"; //四字定
		String erzixian = "^\\d{2}$"; //12;二字现
		String sanzixian = "^\\d{3}$" ; //三字现		
		String sizixian = "^\\d{4}[Xx]$"; //四字现
		pattern.add(erziding1);
		pattern.add(erziding2);
		pattern.add(erziding3);
		pattern.add(erziding4);
		pattern.add(erziding5);
		pattern.add(erziding6);
		pattern.add(sanziding1);
		pattern.add(sanziding2);
		pattern.add(sanziding3);
		pattern.add(sanziding4);	
		pattern.add(siziding);
		pattern.add(erzixian);
		pattern.add(sanzixian);
		pattern.add(sizixian);
		return pattern;
	}
	/**
	 * 判断二字现的类型 即 12 /22 这两种形式的数字
	 * @param erzixian
	 * @return
	 */
	public static int erzixianType(String erzixian){
		if((erzixian.charAt(0)+"").equals(erzixian.charAt(1)+"")){
			return 1;
		}else {
			return 0;
		}
		
		
	}
	
	
	/**
	 * 判断三字现的种类 及 123 112 111这三种类型。
	 * @return
	 */
	public static int sanzixianType(String sanzixianHaoMa){
		Set<String> set = new HashSet<String>();
		for(int i = 0 ; i < sanzixianHaoMa.length(); i++){
			
			set.add(sanzixianHaoMa.charAt(i)+"");
			
		}
		int size = set.size();
		switch (size) {
		case 3:
			return 0;
			
		case 2:
			
			return 1;	
		case 1:
			
			return 2;
		default:
			return -1;
		}
		
		
	}
	/**
	 * 判断四字现的种类 即 1234/1123/1113/1111这四种形式
	 * @param sizixianType
	 * @return
	 */
	public static int sizixianType(String sizixianType){
		Set<String> set = new HashSet<String>();
		for(int i = 0 ; i < sizixianType.length(); i++){
			
			set.add(sizixianType.charAt(i)+"");
			
		}
		int size = set.size();
		switch (size) {
		case 4:
			return 0;
		case 3:
			return 1;
			
		case 2:
			
			return 2;	
		case 1:
			
			return 3;
		default:
			return -1;
		}
	}
	
	
	public static void main(String[] args) {
		
		/*check("12345");
		
		check("X123");
		
		check("1X23");
		check("123X");
		check("12XX");
		check("1X2X");
		check("XX12");
		
		check("1258X");*/
		
		System.out.println(erzixianType("11"));
		
		
		System.out.println(sanzixianType("123"));
		System.out.println(sanzixianType("113"));
		System.out.println(sanzixianType("111"));
		
		System.out.println(sizixianType("1234"));
		System.out.println(sizixianType("1134"));
		System.out.println(sizixianType("1114"));
		System.out.println(sizixianType("1111"));
	}
	
	
	
}
